import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Home from '@/components/Home'
import Login from '@/components/Login'


Vue.use(Router)

export default new Router({
    routes: [{
        path: '/',
        name: 'Home',
        component: Home,
        beforeEnter(to, from, next) {
            // 是否登录，没有登录跳转到 登录
            let username = sessionStorage.getItem("username")
            console.log(username)
            if (username) {
                next() //放行
            } else {
                alert("没有登录，不能访问")
                next("/login")
            }
        },
        children: [{
            path: "/userlist",
            component: () =>
                import ('@/views/user/UserList'),
        }]
    }, {
        path: "/login",
        component: Login
    }]
})